package cn.jasonone.jame.model;

import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import lombok.ToString;

/**
 * 坐标点类
 * @author Jason
 */
@ToString
public class Point {
    /**
     * 横坐标
     */
    private DoubleProperty x=new SimpleDoubleProperty(0);
    /**
     * 纵坐标
     */
    private DoubleProperty y=new SimpleDoubleProperty(0);

    public Point(){
        this(0,0);
    }

    public Point(double x,double y){
        this.moveTo(x,y);
    }

    /**
     * 将指定坐标点与当前坐标绑定
     * @param point 坐标点
     */
    public void bindPoint(Point point){
        this.xProperty().bindBidirectional(point.xProperty());
        this.yProperty().bindBidirectional(point.yProperty());
    }

    /**
     * 解绑坐标点
     * @param point 坐标点
     */
    public void unbindPoint(Point point){
        this.xProperty().unbindBidirectional(point.xProperty());
        this.yProperty().unbindBidirectional(point.yProperty());
    }

    /**
     * 移动指定偏移量
     * @param offsetX 横坐标偏移量
     * @param offsetY 纵坐标偏移量
     */
    public void move(double offsetX,double offsetY){
        this.moveTo(this.getX()+offsetX,this.getY()+offsetY);
    }

    /**
     * 移动到指定位置
     * @param x 横坐标
     * @param y 纵坐标
     */
    public void moveTo(double x,double y){
        this.setX(x);
        this.setY(y);
    }

    /**
     * 移动到指定位置
     * @param point 坐标点
     */
    public void moveTo(Point point){
        this.moveTo(point.getX(),point.getY());
    }

    public double getX() {
        return x.get();
    }

    public DoubleProperty xProperty() {
        return x;
    }

    public void setX(double x) {
        this.x.set(x);
    }

    public double getY() {
        return y.get();
    }

    public DoubleProperty yProperty() {
        return y;
    }

    public void setY(double y) {
        this.y.set(y);
    }
}
